package format;

import java.text.MessageFormat;
import java.util.Date;

public class MessageFormatDemo {

	public static void main(String[] args) {
		// 和可变参数一样,{0}匹配第一个参数,'{}'和正则表达式的\的表示不转义如果要表示一个单引号则用''xxxx''
		String str = MessageFormat.format("{0}abc", 1, 2, 3);
		System.out.println(str);
		String event = "a disturbance in the Force";
		int planet = 7;
		String result = MessageFormat
				.format("At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.",
						planet, new Date(), event);
		System.out.println(result);
		String message = "ok, {0,number,###,###.#} digital";
		Object[] array = new Object[] { new Double(444333333.1415) };
		String value = MessageFormat.format(message, array);
		System.out.println(value);
	}

}
